package org.starsource.forum.server.domain;

import java.io.Serializable;

import org.starsource.forum.client.domain.UserObject;
import org.starsource.forum.client.util.Assertion;


public class User implements HasId, Serializable {
	
	private static final long serialVersionUID = 1888722619809121274L;

	private static org.apache.log4j.Logger logger = org.apache.log4j.LogManager
	.getLogger(User.class.getName());

	private int id;
	
	private String account;

	private String password;
	
	private String name;
	
	private String directory;
	
	public User() {}
	
	public User(String account, String password, String name, String directory) {
		this.account = account;
		this.password =password;
		this.name = name;
		this.directory = directory;
	}

	public User(int id, String account, String password, String name, String directory) {
		this.id = id;
		this.account = account;
		this.password =password;
		this.name = name;
		this.directory = directory;
	}
	
	@Override
	public boolean equals(Object obj) {
		try {
			User object = (User)obj;
			
			if (this.id != object.getId()) {
				logger.debug("User.id is not equal");
				return false;
			}
			if (!Assertion.isEqual(this.account, object.account)) return false;
			if (!Assertion.isEqual(this.password, object.password)) return false;
			if (!Assertion.isEqual(this.name, object.name)) return false;
			if (!Assertion.isEqual(this.directory, object.directory)) return false;
			
			return true;
		} catch (Exception e) {
			return false;
		}
	}
	
	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getAccount() {
		return account;
	}

	public void setAccount(String account) {
		this.account = account;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getDirectory() {
		return directory;
	}

	public void setDirectory(String directory) {
		this.directory = directory;
	}
	
	public UserObject getUserObject() {
		return new UserObject(this.id, this.account, this.password, this.name, this.directory);
	}

}
